package com.yby.dome9;

public class OilStation {
    //判断car对象是汽油车还是柴油车
    public void refuel(Car car){
        if (car instanceof GasCar){
            GasCar gasCar = (GasCar)car;
            gasCar.oilLevel = gasCar.addOilVolume + 10;
            System.out.println("汽油车总共加了"+gasCar.oilLevel);
        }
        if (car instanceof DieCar){
            DieCar dieCar = (DieCar) car;
           dieCar.oilLevel = dieCar.addOilVolume + 20;
            System.out.println("柴油车总共加了"+dieCar.oilLevel);
        }
    }

    public static void main(String[] args) {
        Car car = new GasCar();
        Car car1 = new DieCar();
        OilStation oilStation = new OilStation();
        car.toOilStation(car);
        oilStation.refuel(car);
        car1.toOilStation(car1);
        oilStation.refuel(car1);
    }
}
